var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        tabs: [ {
            title: "正在拼团",
            id: 0
        }, {
            title: "拼团成功",
            id: 1
        }, {
            title: "拼团失败",
            id: 2
        } ],
        networkLoading: !1,
        activeName: 0,
        dataList: [],
        loading: !1,
        isLoadMore: !0,
        optionsId: 0,
        popupSpecs: !1,
        goods: {},
        specs: [],
        options: [],
        groupLevel: [],
        level_id: 0,
        activity_option_id: "",
        alliance_detail_id: "",
        groupModel: "",
        special_options: "",
        selectGroupInfo: {}
    },
    onLoad: function(t) {
        this.data.groupModel = 0, this.data.dataList = [], this.getData(!0);
    },
    buyClicked: function(t) {
        console.log(t);
        var a = this.data.goods.id, i = t.detail.optionsId, e = this.data.alliance_detail_id, o = this.data.activity_option_id;
        wx.navigateTo({
            url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=groupWork&goodsId=" + a + "&optionsId=" + i + "&total=1&alliance_detail_id=" + e + "&activity_option_id=" + o
        });
    },
    getGoods: function(t) {
        var i = this, e = t.currentTarget.dataset, o = e.activityid, s = e.specid, d = e.id;
        this.data.alliance_detail_id = d, a._postNetWork({
            url: a.getNetAddresss("plugin.group-work.frontend.modules.goods.controllers.detail.index"),
            data: {
                record_id: o
            },
            success: function(t) {
                var e = t.data;
                if (1 != e.result) return a.tips(e.msg);
                var o = {};
                o.id = e.data.goods_id, o.has_option = e.data.goods_info.has_option, o.thumb = e.data.goods_info.thumb, 
                o.unit = e.data.goods_info.sku;
                var d = e.data.specs.filter(function(t) {
                    if (t.id == s) return o.price = t.min_price, t;
                });
                i.setData({
                    goods: o,
                    specs: e.data.goods_info.has_many_specs,
                    options: e.data.goods_info.has_many_options,
                    groupModel: s,
                    groupLevel: d,
                    special_options: e.data.special_options
                }), i.setData({
                    popupSpecs: !0
                }), 0 == i.data.goods.has_option && i.setGroupInfo(0);
            }
        });
    },
    skuSelected: function(t) {
        t && (this.data.optionsId = t.detail), this.setGroupInfo(this.data.optionsId);
    },
    setGroupInfo: function(t) {
        for (var a = 0; a < this.data.special_options.length; a++) {
            if (this.data.special_options[a].option_id == this.data.optionsId) return this.data.selectGroupInfo = this.data.special_options[a].activity_options, 
            this.selectComponent("#yzSpecs").setData({
                popStock: this.data.special_options[a].stock
            }), void this.selectGroup(this.data.groupModel);
        }
    },
    selectGroup: function(t) {
        this.data.groupModel = t;
        var i = "";
        t && (1 == this.data.goods.has_option ? this.data.optionsId ? (i = this.data.selectGroupInfo.filter(function(a) {
            if (a.spec_id == t) return a.price;
        }), this.selectComponent("#yzSpecs").setData({
            popPrice: i[0].price
        }), this.data.activity_option_id = i[0].id) : (a.tips("请选择商品规格！"), this.data.groupModel = "") : (this.data.selectGroupInfo = this.data.special_options[0].activity_options, 
        i = this.data.selectGroupInfo.filter(function(a) {
            if (a.spec_id == t) return a.price;
        }), this.selectComponent("#yzSpecs").setData({
            popPrice: i[0].price
        }), this.data.activity_option_id = i[0].id));
    },
    getTab: function(t) {
        this.setData({
            activeName: t.detail.name
        }), this.getData(!1);
    },
    getData: function(i) {
        var e = this, o = this.data.activeName;
        !i && this.data.dataList[o].list.length > 0 || (this.setData({
            networkLoading: !1
        }), a._postNetWork({
            url: a.getNetAddresss("plugin.group-work.frontend.modules.alliance.controllers.records.index"),
            data: {
                status: [ "1", "2", "-1" ][o]
            },
            success: function(s) {
                var d;
                e.setData({
                    networkLoading: !0
                });
                var n = s.data;
                if (1 != n.result) return a.tips(n.msg);
                var r = e.data.dataList;
                i && (e.data.tabs.forEach(function(t, a) {
                    r.push({
                        isLoadMore: !0,
                        page: 1,
                        total_page: 0,
                        list: []
                    });
                }), e.setData({
                    dataList: r
                }));
                for (var p = n.data.page_list.data, c = 0; c < p.length; c++) p[c].timeDifference = a.getTimeDifference(p[c].remain_time);
                e.setData((t(d = {}, "dataList[" + o + "].list", p), t(d, "dataList[" + o + "].total_page", n.data.page_list.last_page), 
                t(d, "dataList[" + o + "].isLoadMore", 1 != n.data.page_list.last_page), d));
            }
        }));
    },
    getMore: function() {
        var i = this, e = this.data.activeName;
        if (!(this.data.dataList[e].isLoadMore || this.data.dataList[e].page >= this.data.dataList[e].total_page)) {
            this.data.dataList[e].isLoadMore = !0, this.data.dataList[e].page += 1;
            a._postNetWork({
                url: a.getNetAddresss("plugin.group-work.frontend.modules.alliance.controllers.records.index"),
                data: {
                    status: [ "1", "2", "-1" ][e],
                    page: this.data.dataList[e].page
                },
                success: function(o) {
                    var s = o.data;
                    if (i.data.dataList[e].isLoadMore = !1, 1 != s.result) return a.tips(s.msg);
                    for (var d = s.data.page_list.data, n = 0; n < d.length; n++) d[n].timeDifference = a.getTimeDifference(d[n].remain_time);
                    i.setData(t({}, "dataList[" + e + "].list", i.data.dataList[e].list.concat(d)));
                }
            });
        }
    },
    gotoDetail: function(t) {
        var a = t.currentTarget.dataset, i = a.allianceid, e = a.id;
        wx.navigateTo({
            url: "/packageI/groupWork/groupWorkDetail/groupWorkDetail?allianceid=" + i + "&id=" + e
        });
    },
    toOrder: function(t) {
        var a = t.currentTarget.dataset.orderid;
        wx.navigateTo({
            url: "/packageA/member/orderdetail/orderdetail?order_id=" + a + "&orderType=groupWork"
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getMore();
    },
    onShareAppMessage: function() {}
});